home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glypha 3.02 / source / Code ƒ / B-Dialogs.p < prev    next >
Encoding:
Text File  |  1990-09-15  |  15.8 KB  |  481 lines  |  [TEXT/PJMM]

  1. unit Dialogs;
  2.  
  3. interface
  4.  
  5.     var
  6.         rightOffset, downOffset: Integer;
  7.  
  8.     procedure D_ConfigureGameWndo (var mortals, level, toDelay: Integer; var soundOn: Boolean; cantSing: Boolean);
  9.     procedure D_ControlsWndo (var keyboardControl: Boolean);
  10.     procedure WhosHiScore (var theName: Str255);
  11.  
  12. implementation
  13.  
  14.     const                            {These are the item numbers for controls in the Dialog    }
  15.         I_Okay = 1;                    {They are found in the .RSRC fork of Glypha                }
  16.         I_Cancel = 2;
  17.         I_Sound_OFF = 3;
  18.         I_Sound_ON = 4;
  19.         I_Fast = 5;
  20.         I_Fastest = 6;
  21.         I_Slow = 14;
  22.         I_Slowest = 15;
  23.  
  24.         I_Static_Text = 2;
  25.         I_Static_Text3 = 3;
  26.         I_Static_Text7 = 7;
  27.         I_Static_Text8 = 8;
  28.         I_Static_Text10 = 9;
  29.         I_Edit_Text = 4;
  30.         I_Edit_Text6 = 5;
  31.         I_Edit_Text10 = 10;
  32.         I_Edit_Text13 = 11;
  33.         I_Rectanglex12 = 12;
  34.         I_Rectanglex13 = 13;
  35.         I_Drawn_line = 14;
  36.         I_Drawn_line18 = 15;
  37.         I_Keyboard = 3;
  38.         I_Mouse = 4;
  39.         I_Static_Text5 = 5;
  40.         I_Iconx6 = 6;
  41.         I_Iconx7 = 7;
  42.         I_Iconx8 = 8;
  43.         I_Iconx9 = 9;
  44.         I_Iconx10 = 10;
  45.         I_Iconx11 = 11;
  46.         I_Iconx12 = 12;
  47.         I_Iconx13 = 13;
  48.         I_Rectanglex14 = 14;
  49.         I_Rectanglex15 = 15;
  50.         I_Rectanglex16 = 16;
  51.     var
  52.         GetSelection: DialogPtr;             {Name of dialog}
  53.         tempRect: Rect;                      {Temporary tectangle}
  54.         DType: Integer;                      {Type of dialog item}
  55.         Index: Integer;                      {For looping}
  56.         DItem: Handle;                       {Handle to the dialog item}
  57.         CItem, CTempItem: controlhandle;     {Control handle}
  58.         sTemp: Str255;                       {Get text entered, temp holding}
  59.         itemHit: Integer;                    {Get selection}
  60.         temp: Integer;                       {Get selection, temp holding}
  61.         ThisEditText: TEHandle;              {Handle to get the Dialogs TE record}
  62.         TheDialogPtr: DialogPeek;            {Pointer to Dialogs definition record, contains the TE record}
  63.         ExitDialog, keepIt: boolean;
  64.  
  65. {==========================================================}
  66.  
  67.     procedure D_ConfigureGameWndo;
  68.         var
  69.             soundCopy, keepIt: Boolean;
  70.             delayCopy, levelCopy, mortalsCopy, rightOff, downOff, Index: Integer;
  71.             theValue: Integer;
  72.             nTemp: LongInt;
  73.         procedure Refresh_Dialog;            {Refresh the dialogs non-controls    }
  74.             var
  75.                 rTempRect: Rect;
  76.         begin
  77.             rTempRect := tempRect;
  78.             PenSize(1, 1);
  79.             MoveTo(8, 80);
  80.             LineTo(340, 80);
  81.             MoveTo(171, 40);
  82.             LineTo(171, 134);
  83.             SetRect(tempRect, 6, 40, 341, 135);
  84.             FrameRect(tempRect);
  85.             MoveTo(7, 29);
  86.             LineTo(340, 29);
  87.             LineTo(340, 6);
  88.             SetRect(tempRect, 6, 5, 340, 29);
  89.             FrameRect(tempRect);
  90.             SetRect(tempRect, 222, 146, 299, 173);
  91.             PenSize(3, 3);
  92.             FrameRoundRect(tempRect, 15, 15);
  93.             PenSize(1, 1);
  94.             tempRect := rTempRect;
  95.         end;
  96.  
  97.     begin
  98.         levelCopy := level;
  99.         mortalsCopy := mortals;
  100.         soundCopy := soundOn;
  101.         delayCopy := toDelay;
  102.         GetSelection := GetNewDialog(3, nil, Pointer(-1));    {Bring in the dialog resource        }
  103.         with GetSelection^.portBits do
  104.             begin
  105.                 rightOff := rightOffset - bounds.left;
  106.                 downOff := downOffset - bounds.top;
  107.             end;
  108.         MoveWindow(GetSelection, rightOff, downOff, FALSE);
  109.         ShowWindow(GetSelection);
  110.         SelectWindow(GetSelection);                        {Lets see it                            }
  111.         SetPort(GetSelection);                                {Perpare to add conditional text    }
  112.         TheDialogPtr := DialogPeek(GetSelection);{Get to the inner record            }
  113.         ThisEditText := TheDialogPtr^.textH;    {Get to the TE record            }
  114.         HLock(Handle(ThisEditText));                    {Lock it for safety                }
  115.         ThisEditText^^.txSize := 12;                    {TE Point size                        }
  116.         TextSize(12);                                                    {Window Point size                }
  117.         ThisEditText^^.txFont := systemFont;    {TE Font ID                                }
  118.         TextFont(systemFont);                                    {Window Font ID                        }
  119.         ThisEditText^^.txFont := 0;                        {TE Font ID                                }
  120.         ThisEditText^^.fontAscent := 12;            {Font ascent                            }
  121.         ThisEditText^^.lineHeight := 12 + 3 + 1;{Font ascent + descent + leading    }
  122.         HUnLock(Handle(ThisEditText));                {UnLock handle when done    }
  123.         if (soundOn) then
  124.             begin
  125.                 GetDItem(GetSelection, I_Sound_ON, DType, DItem, tempRect);
  126.                 CItem := Pointer(DItem);
  127.                 SetCtlValue(CItem, 1);
  128.             end
  129.         else
  130.             begin
  131.                 GetDItem(GetSelection, I_Sound_OFF, DType, DItem, tempRect);
  132.                 CItem := Pointer(DItem);
  133.                 SetCtlValue(CItem, 1);
  134.             end;
  135.         if (cantSing) then                    {cantSing is TRUE if run under older than System 6.0    }
  136.             begin
  137.                 GetDItem(GetSelection, I_Sound_ON, DType, DItem, tempRect);
  138.                 CItem := Pointer(DItem);
  139.                 HiliteControl(CItem, 255);
  140.                 GetDItem(GetSelection, I_Sound_OFF, DType, DItem, tempRect);
  141.                 CItem := Pointer(DItem);
  142.                 HiliteControl(CItem, 255);
  143.             end;
  144.  
  145.         case toDelay of
  146.             0: 
  147.                 GetDItem(GetSelection, I_Fastest, DType, DItem, tempRect);
  148.             1: 
  149.                 GetDItem(GetSelection, I_Fast, DType, DItem, tempRect);
  150.             3: 
  151.                 GetDItem(GetSelection, I_Slow, DType, DItem, tempRect);
  152.             4: 
  153.                 GetDItem(GetSelection, I_Slowest, DType, DItem, tempRect);
  154.             otherwise
  155.                 begin
  156.                     GetDItem(GetSelection, I_Fastest, DType, DItem, tempRect);
  157.                 end;
  158.         end;
  159.         CItem := Pointer(DItem);
  160.         SetCtlValue(CItem, 1);            {Select to slower}
  161.  
  162.         GetDItem(GetSelection, I_Edit_Text10, DType, DItem, tempRect);
  163.         NumToString(mortalsCopy, sTemp);
  164.         SetIText(DItem, sTemp);
  165.         GetDItem(GetSelection, I_Edit_Text13, DType, DItem, tempRect);
  166.         NumToString(levelCopy, sTemp);
  167.         SetIText(DItem, sTemp);
  168.         SelIText(GetSelection, I_Edit_Text13, 0, 2);
  169.         Refresh_Dialog;
  170.         ExitDialog := FALSE;                    {Do not exit dialog handle loop yet    }
  171.         repeat                                                {Start of dialog handle loop                }
  172.             ModalDialog(nil, itemHit);    {Wait until an item is hit                    }
  173.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect);    {Get item information    }
  174.             CItem := Pointer(DItem);        {Get the control handle                            }
  175.             if (ItemHit = I_Okay) then    {Handle the Button being pressed                    }
  176.                 begin
  177.                     GetDItem(GetSelection, I_Edit_Text10, DType, DItem, tempRect); {Get the item handle}
  178.                     GetIText(DItem, sTemp);
  179.                     StringToNum(sTemp, nTemp);
  180.                     mortalsCopy := LoWord(nTemp);
  181.  
  182.                     GetDItem(GetSelection, I_Edit_Text13, DType, DItem, tempRect); {Get the item handle}
  183.                     GetIText(DItem, sTemp);            {Get the text entered                                }
  184.                     StringToNum(sTemp, nTemp);
  185.                     levelCopy := LoWord(nTemp);
  186.  
  187.                     if ((levelCopy < 1) or (levelCopy > 99)) then
  188.                         begin
  189.                             GetDItem(GetSelection, I_Edit_Text13, DType, DItem, tempRect);
  190.                             NumToString(levelCopy, sTemp);
  191.                             SetIText(DItem, sTemp);
  192.                             levelCopy := level;
  193.                         end;
  194.                     if ((mortalsCopy < 1) or (mortalsCopy > 99)) then
  195.                         begin
  196.                             GetDItem(GetSelection, I_Edit_Text10, DType, DItem, tempRect);
  197.                             NumToString(mortalsCopy, sTemp);
  198.                             SetIText(DItem, sTemp);
  199.                             mortalsCopy := mortals;
  200.                         end;
  201.                     if ((mortalsCopy > 0) and (mortalsCopy < 100)) and ((levelCopy > 0) and (levelCopy < 100)) then
  202.                         begin
  203.                             level := levelCopy;
  204.                             mortals := mortalsCopy;
  205.                             keepIt := TRUE;
  206.                             ExitDialog := TRUE;
  207.                         end;
  208.                     Refresh_Dialog;
  209.                 end;
  210.             if (ItemHit = I_Cancel) then
  211.                 begin
  212.                     keepIt := FALSE;
  213.                     ExitDialog := TRUE;
  214.                     Refresh_Dialog;
  215.                 end;
  216.             if (ItemHit >= I_Sound_OFF) and (ItemHit <= I_Sound_ON) then {Handle the Radio selection}
  217.                 begin
  218.                     for Index := I_Sound_OFF to I_Sound_ON do {Clear all other radios}
  219.                         begin
  220.                             GetDItem(GetSelection, Index, DType, DItem, tempRect); {Get the Radio handle}
  221.                             CTempItem := Pointer(DItem);    {Convert to a control handle}
  222.                             SetCtlValue(CTempItem, 0);      {Turn the radio selection OFF}
  223.                         end;                              {End of clear the radio selections loop}
  224.                     SetCtlValue(CItem, 1);            {Turn the one radio selection ON}
  225.                     GetDItem(GetSelection, I_Sound_OFF, DType, DItem, tempRect);
  226.                     theValue := GetCtlValue(Pointer(DItem));
  227.                     if (theValue = 1) then
  228.                         soundCopy := FALSE
  229.                     else
  230.                         soundCopy := TRUE;
  231.                 end;
  232.             if ((ItemHit = I_Slowest) or (ItemHit = I_Fastest) or (ItemHit = I_Fast) or (ItemHit = I_Slow)) then {Handle the Radio selection}
  233.                 begin
  234.                     GetDItem(GetSelection, I_Slowest, DType, DItem, tempRect);    {Get the Radio handle}
  235.                     CTempItem := Pointer(DItem);                                        {Convert to a control handle            }
  236.                     SetCtlValue(CTempItem, 0);                                        {Turn the radio selection OFF                }
  237.                     GetDItem(GetSelection, I_Fastest, DType, DItem, tempRect);    {Get the Radio handle}
  238.                     CTempItem := Pointer(DItem);                                        {Convert to a control handle            }
  239.                     SetCtlValue(CTempItem, 0);                                        {Turn the radio selection OFF                }
  240.                     GetDItem(GetSelection, I_Fast, DType, DItem, tempRect);        {Get the Radio handle}
  241.                     CTempItem := Pointer(DItem);                                        {Convert to a control handle            }
  242.                     SetCtlValue(CTempItem, 0);                                        {Turn the radio selection OFF                }
  243.                     GetDItem(GetSelection, I_Slow, DType, DItem, tempRect);        {Get the Radio handle}
  244.                     CTempItem := Pointer(DItem);                                        {Convert to a control handle            }
  245.                     SetCtlValue(CTempItem, 0);                                        {Turn the radio selection OFF                }
  246.  
  247.                                                                     {End of clear the radio selections loop    }
  248.                     SetCtlValue(CItem, 1);                                                    {Turn the one radio selection ON    }
  249.  
  250.                     GetDItem(GetSelection, I_Fastest, DType, DItem, tempRect);
  251.                     theValue := GetCtlValue(Pointer(DItem));
  252.                     if (theValue = 1) then
  253.                         delayCopy := 0;
  254.  
  255.                     GetDItem(GetSelection, I_Fast, DType, DItem, tempRect);
  256.                     theValue := GetCtlValue(Pointer(DItem));
  257.                     if (theValue = 1) then
  258.                         delayCopy := 1;
  259.  
  260.                     GetDItem(GetSelection, I_Slow, DType, DItem, tempRect);
  261.                     theValue := GetCtlValue(Pointer(DItem));
  262.                     if (theValue = 1) then
  263.                         delayCopy := 3;
  264.  
  265.                     GetDItem(GetSelection, I_Slowest, DType, DItem, tempRect);
  266.                     theValue := GetCtlValue(Pointer(DItem));
  267.                     if (theValue = 1) then
  268.                         delayCopy := 4;
  269.  
  270.                 end;
  271.         until ExitDialog;
  272.         if (keepIt) then
  273.             begin
  274.                 soundOn := soundCopy;
  275.                 toDelay := delayCopy;
  276.             end;
  277.         DisposDialog(GetSelection);
  278.     end;
  279.  
  280. {===========================================================}
  281.  
  282.     function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  283.         var
  284.             MyPt: Point;
  285.     begin
  286.         MyFilter := FALSE;
  287.         if (theEvent.what = MouseDown) then
  288.             begin
  289.                 MyPt := theEvent.where;
  290.                 with theDialog^.portBits.bounds do
  291.                     begin
  292.                         myPt.h := myPt.h + left;
  293.                         myPt.v := myPt.v + top;
  294.                     end;
  295.             end;
  296.     end;
  297.  
  298. {===========================================================}
  299.  
  300.     procedure D_ControlsWndo;
  301.  
  302.         var
  303.             Index, rightOff, downOff: Integer;
  304.  
  305.         procedure Refresh_Dialog;
  306.             var
  307.                 rTempRect: Rect;
  308.         begin
  309.             rTempRect := tempRect;
  310.             PenSize(1, 1);
  311.             MoveTo(127, 114);
  312.             LineTo(265, 114);
  313.             LineTo(265, 36);
  314.             SetRect(TempRect, 126, 35, 265, 114);
  315.             FrameRect(TempRect);
  316.             MoveTo(127, 164);
  317.             LineTo(265, 164);
  318.             LineTo(265, 121);
  319.             SetRect(TempRect, 126, 120, 265, 164);
  320.             FrameRect(TempRect);
  321.             MoveTo(7, 32);
  322.             LineTo(267, 32);
  323.             LineTo(267, 6);
  324.             SetRect(TempRect, 6, 5, 267, 32);
  325.             FrameRect(TempRect);
  326.             SetRect(tempRect, 172, 176, 257, 203);
  327.             PenSize(3, 3);
  328.             FrameRoundRect(tempRect, 15, 15);
  329.             PenSize(1, 1);
  330.             tempRect := rTempRect;
  331.         end;
  332.  
  333.     begin
  334.         GetSelection := GetNewDialog(4, nil, Pointer(-1));
  335.         with GetSelection^.portBits do
  336.             begin
  337.                 rightOff := rightOffset - bounds.left;
  338.                 downOff := downOffset - bounds.top;
  339.             end;
  340.         MoveWindow(GetSelection, rightOff, downOff, FALSE);
  341.         ShowWindow(GetSelection);
  342.         SelectWindow(GetSelection);
  343.         SetPort(GetSelection);
  344.         TheDialogPtr := DialogPeek(GetSelection);
  345.         ThisEditText := TheDialogPtr^.textH;
  346.         HLock(Handle(ThisEditText));
  347.         ThisEditText^^.txSize := 12;
  348.         TextSize(12);
  349.         ThisEditText^^.txFont := systemFont;
  350.         TextFont(systemFont);
  351.         ThisEditText^^.txFont := 0;
  352.         ThisEditText^^.fontAscent := 12;
  353.         ThisEditText^^.lineHeight := 12 + 3 + 1;
  354.         HUnLock(Handle(ThisEditText));
  355.         if (keyboardControl) then
  356.             GetDItem(GetSelection, I_Keyboard, DType, DItem, tempRect)
  357.         else
  358.             GetDItem(GetSelection, I_Mouse, DType, DItem, tempRect);
  359.         CItem := Pointer(DItem);
  360.         SetCtlValue(CItem, 1);
  361.         Refresh_Dialog;
  362.         ExitDialog := FALSE;
  363.         repeat
  364.             ModalDialog(nil, itemHit);
  365.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect);
  366.             CItem := Pointer(DItem);
  367.             if (ItemHit = I_Okay) then
  368.                 begin
  369.                     keepIt := TRUE;
  370.                     ExitDialog := TRUE;
  371.                     Refresh_Dialog;
  372.                 end;
  373.             if (ItemHit = I_Cancel) then
  374.                 begin
  375.                     keepIt := FALSE;
  376.                     ExitDialog := TRUE;
  377.                     Refresh_Dialog;
  378.                 end;
  379.             if (ItemHit >= I_Keyboard) and (ItemHit <= I_Mouse) then
  380.                 begin
  381.                     for Index := I_Keyboard to I_Mouse do
  382.                         begin
  383.                             GetDItem(GetSelection, Index, DType, DItem, tempRect);
  384.                             CTempItem := Pointer(DItem);
  385.                             SetCtlValue(CTempItem, 0);
  386.                         end;
  387.                     SetCtlValue(CItem, 1);
  388.                 end;
  389.         until ExitDialog;
  390.         Index := I_Keyboard;
  391.         repeat
  392.             GetDItem(GetSelection, Index, DType, DItem, tempRect);
  393.             CItem := Pointer(DItem);
  394.             temp := GetCtlValue(CItem);
  395.             Index := Index + 1;
  396.         until (temp <> 0) or (Index > I_Mouse);
  397.         temp := Index - I_Keyboard + 1;
  398.         if (keepIt) then
  399.             begin
  400.                 if (temp = 3) then
  401.                     keyboardControl := FALSE
  402.                 else
  403.                     keyboardControl := TRUE;
  404.             end;
  405.         DisposDialog(GetSelection);
  406.     end;
  407.  
  408. {===========================================}
  409.  
  410.     procedure WhosHiScore;
  411.         var
  412.             excessSpace, rightOff, downOff: Integer;
  413.             dotFiller, space: Str255;
  414.  
  415.         procedure Refresh_Dialog;                {This draws the rounded-rectangular        }
  416.             var                                            {border around the Okay button so that        }
  417.                 rTempRect: Rect;                            {the user knows it is the default button.        }
  418.         begin
  419.             PenNormal;
  420.             PenSize(3, 3);
  421.             SetRect(rTempRect, 167, 36, 251, 65);
  422.             FrameRoundRect(rTempRect, 13, 13);
  423.         end;
  424.  
  425.     begin                                                            {Start of dialog handler}
  426.         GetSelection := GetNewDialog(999, nil, Pointer(-1));{Bring in the dialog resource}
  427.         with GetSelection^.portBits do
  428.             begin
  429.                 rightOff := rightOffset - bounds.left;
  430.                 downOff := downOffset - bounds.top;
  431.             end;
  432.         MoveWindow(GetSelection, rightOff, downOff, FALSE);
  433.         ShowWindow(GetSelection);
  434.         SelectWindow(GetSelection);                                {Lets see it}
  435.         SetPort(GetSelection);                                        {Perpare to add conditional text}
  436.         TheDialogPtr := DialogPeek(GetSelection);    {Get to the inner record}
  437.         ThisEditText := TheDialogPtr^.textH;            {Get to the TE record}
  438.         HLock(Handle(ThisEditText));                            {Lock it for safety}
  439.         ThisEditText^^.txSize := 12;                            {TE Point size}
  440.         TextSize(12);                                                            {Window Point size}
  441.         ThisEditText^^.txFont := systemFont;          {TE Font ID}
  442.         TextFont(systemFont);                                            {Window Font ID}
  443.         ThisEditText^^.txFont := 0;                                {TE Font ID}
  444.         ThisEditText^^.fontAscent := 12;                    {Font ascent}
  445.         ThisEditText^^.lineHeight := 12 + 3 + 1;    {Font ascent + descent + leading}
  446.         HUnLock(Handle(ThisEditText));                        {UnLock the handle when done}
  447.         GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect);
  448.         SetIText(DItem, theName);                                    {Set the default text}
  449.         SelIText(GetSelection, I_Edit_Text, 0, 15);{Select the text}
  450.         ExitDialog := FALSE;                                            {Don't exit dialog loop yet}
  451.         Refresh_Dialog;
  452.         repeat                                                                        {Start of dialog loop}
  453.             ModalDialog(nil, itemHit);                            {Wait until item is hit}
  454.             GetDItem(GetSelection, itemHit, DType, DItem, tempRect); {Get item information}
  455.             CItem := Pointer(DItem);                                {Get the control handle}
  456.             if (ItemHit = I_Okay) then                            {Handle the Button pressed}
  457.                 begin
  458.                     GetDItem(GetSelection, I_Edit_Text, DType, DItem, tempRect); {Get the item handle}
  459.                     GetIText(DItem, sTemp);                            {Get the text entered}
  460.                     if (LENGTH(sTemp) > 15) then                {Make sure it's less than 15 characters}
  461.                         theName := COPY(sTemp, 1, 15)            {Just clip the first 15 if it is too long}
  462.                     else
  463.                         begin
  464.                             if (LENGTH(sTemp) < 15) then
  465.                                 begin
  466.                                     space := '               ';
  467.                                     excessSpace := 15 - LENGTH(sTemp);
  468.                                     dotFiller := COPY(space, 1, excessSpace);
  469.                                     sTemp := CONCAT(sTemp, dotfiller);
  470.                                 end;
  471.                             theName := sTemp;                            {Otherwise, take it as is}
  472.                         end;
  473.                     ExitDialog := TRUE;                                {Exit the dialog when this selection is made}
  474.                 end;                                                {End for this item selected}
  475.         until ExitDialog;                                        {Handle dialog items until exit selected}
  476.         DisposDialog(GetSelection);                        {Flush the dialog out of memory}
  477.     end;                                                        {End of procedure}
  478.  
  479. {=============================================================}
  480.  
  481. end.